
const http = require("http");
const db = require("./db");
const qs = require("querystring");
http.createServer((req,res)=>{
    res.setHeader("Access-Control-Allow-Origin", "*")//跨域
    res.setHeader('Content-Type', 'text/html; charset=utf-8');//设置乱码
    if(req.url=="/favicon.ico"){
        return;
    }
    let str = req.url.split("?")[1];
    str = qs.parse(str)
    console.log(str);
    // let sql  = `select * from user where name like '${str.name}'`;
    // let sql = `select * from user where name like '%${str.name}%'`
    let sql = "select * from user";
    db(sql,(err,result)=>{
        if(err){
            throw err;
        }
        let data = {
            code:200,
            msg:"查询成功",
            data:result
        }
        res.end(JSON.stringify(data))
    })

}).listen(3000)

console.log(3000);